
import { patchRouter } from '../utils'
import { turnApp } from './routerHandle'

export const rewriteRouter = () => {
  console.log("rewriteRouter=============================================",)
  // micro_push： 自定义事件
  window.history.pushState = patchRouter(window.history.pushState, 'micro_push')
  window.history.replaceState = patchRouter(window.history.replaceState, 'micro_replace')

  window.addEventListener('micro_push', turnApp)
  window.addEventListener('micro_replace', turnApp)
  
  // 监听浏览器前进后退按钮
  window.onpopstate = function() {
    turnApp()
  }
}

